package com.guc.dao;

import com.guc.pojo.User;

import java.util.ArrayList;

/**
 *使用jdbc来操作数据库  增删改查
 * 1.加载
 * 2.获取连接
 * 3.获取执行sql对象（sql注入）
 * 4.执行sql
 * 5.解析结果
 * 6.关闭资源
 */
public class UserDaoImpl extends BaseDao implements UserDao {
    @Override
    public int addUser(String name, String pwd) {
        String sql = "insert INTo user (name,password) VALUES ('"+name+"''"+pwd+"')";
        int updata = updata(sql);
        return updata;
    }

    @Override
    public User login(String name, String pwd) {
        String sql = "SELECT * FROM user where name= '"+name +"' and password = '"+pwd+"'";
        ArrayList<Object> query = query(sql, User.class);// d登录成功的用户
        if(query.size()>0){
            return (User)query.get(0);
        }
        return null;
    }
}
